<HTML><HEAD><TITLE>collection_to_list(+Collection, ?List)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(lists)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>collection_to_list(+Collection, ?List)</H1>
Convert a "collection" into a list
<H2>Description</H2>
   Converts various "collection" data structures into a list.  Fails if it
   does not know how to do this.  The supported collection types are:
<DL>
   <DT>List<DD>
	The list is returned unchanged.
   <DT>Array<DD>
	The array is flattened into a list using flatten_array/2.
   <DT>Subscript reference (Array[...])<DD>
	subscript/3 is called to evaluate the subscript reference.  Note
	that the result is not flattened, so if subscript/3 results in a
	nested list, the result is a nested list.  However if the result is
	a single element of the array that is not a list, this is converted
	into a list containing that element.
   <DT>flatten(Collection)<DD>
	Calls collection_to_list/2 on Collection and then flattens the
	result using flatten/2.
   <DT>flatten(MaxDepth, Collection)<DD>
	Calls collection_to_list/2 on Collection and then flattens the
	result up to MaxDepth levels of nesting using flatten/3.
</DL>

<H3>Modes and Determinism</H3><UL>
<LI>collection_to_list(+, -) is det
</UL>
<H2>Examples</H2>
<PRE>   ?- collection_to_list([a,b,[c,d]], List).
   List = [a, b, [c, d]]
   Yes
   ?- collection_to_list([](a,b,[c,d]), List).
   List = [a, b, [c, d]]
   Yes
   ?- collection_to_list([]([](a,b),[](c,d)), List).
   List = [a, b, c, d]
   Yes
   ?- A = []([](a,b),[](c,d)),
      collection_to_list(A[1..2,1], List).
   List = [a, c]
   Yes
   ?- A = []([](a,b,c),[](d,e,f)),
      collection_to_list(A[1..2,2..3], List).
   List = [[b, c], [e, f]]
   Yes
   ?- collection_to_list(flatten([a,b,[c,d]]), List).
   List = [a, b, c, d]
   Yes
   ?- collection_to_list(flatten([](a,b,[c,d])), List).
   List = [a, b, c, d]
   Yes
   ?- A = []([](a,b,c),[](d,e,f)),
      collection_to_list(flatten(A[1..2,2..3]), List).
   List = [b, c, e, f]
   Yes
   ?- L = [[a,b],[[c,d],[e,f]],g],
      collection_to_list(flatten(1, L), List).
   List = [a, b, [c, d], [e, f], g]
   Yes
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/termmanip/subscript-3.html">subscript / 3</A>, <A HREF="../../lib/lists/flatten-2.html">flatten / 2</A>, <A HREF="../../lib/lists/flatten-3.html">flatten / 3</A>, <A HREF="../../kernel/termmanip/flatten_array-2.html">flatten_array / 2</A>
</BODY></HTML>
